﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterfaceFiles
{
  public class TextInterfaceRecord : BaseInterfaceRecord, IInterfaceRecord
  {
    public TextInterfaceRecord(IInterfaceReader reader, IInterfaceWriter writer,
      List<string> nodes)
      : base(reader, writer, nodes)
    {
    }

    public override void Write()
    {
      Write(this);
    }

    public void Write(IInterfaceRecord record)
    {
      JulianDate julDate = (JulianDate)record.RecordDateTime;
      writer.WriteInt(julDate.Raw);
      Double secondsOfDay = record.RecordDateTime.TimeOfDay.TotalSeconds;
      writer.WriteDouble(secondsOfDay);
      writer.WriteDouble(record.TimeStep);
      writeData(record.Data);
      writer.FlushRecord();
    }

    private void writeData(Dictionary<string, double> data)
    {
      List<string> keys = data.Keys.ToList();
      for (int i = 0; i < keys.Count; i++)
      {
        writer.WriteDouble(data[keys[i]]);
      }
    }
  }
}
